-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP v2 - deprecated] Unlikelihood token loss #2011
base: master
Are you sure you want to change the base?
[WIP v2 - deprecated] Unlikelihood token loss #2011
Conversation
funboarder13920
commented
Feb 19, 2021
- Implement unlikelihood loss from Neural Text Generation with Unlikelihood Training
- Tests for unlikelihood loss
- Class refactoring for LossComputeBase
- Fix ppl in statistics that used to be based on the loss which could be different from NLLLoss
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few comments.
.github/workflows/push.yml
Outdated
-heads 4 -transformer_ff 64 \ | ||
-word_vec_size 16 -report_every 5 \ | ||
-rnn_size 16 -train_steps 10 | ||
- name: Test LM training with unlieklihood loss |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo 'unlikelihood'
opt.label_smoothing, len(tgt_field.vocab), | ||
ignore_index=padding_idx | ||
) | ||
elif opt.unlikelihood_coeff > 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we assert in the opts validation that unlikelihood_coeff
isn't compatible with label_smoothing
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can make them mutually exclusive with the parser or I can make both of them compatible at the same time as unlikelihood_coeff can be added to any loss (but label smoothing and unlikelihood are contradictory)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, let's go for the mutually exclusive way.
@@ -177,7 +177,7 @@ def forward(self, scores, align, target): | |||
return loss | |||
|
|||
|
|||
class CommonCopyGeneratorLossCompute(CommonLossCompute): | |||
class CommonCopyGeneratorLossCompute(LossComputeBase): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure to grasp the whole rationale behind the CommonLossCompute
/LossComputeBase
refactoring. Is the last big remaining difference only the log_ppl computation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Underlying question is: do we really need both CommonLossCompute
and LossComputeBase
anymore?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The _compute_loss, _make_shard_state and the way to use the generator are different between CopyGeneratorLoss and the other classes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do it in one class, the code is already not very clear, it's not going to be worse. If we do that CopyGenerator will override _compute_loss, _compute_log_ppl and _compute_alignement_loss will only be used in the compute_loss of the main class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do it in one class, the code is already not very clear, it's not going to be worse. If we do that CopyGenerator will override _compute_loss, _compute_log_ppl and _compute_alignement_loss will only be used in the compute_loss of the main class
Yes I think this might be a bit better to explicitly override this method instead of having a full class that we don't really know what it's for unless we look at this specific CopyGeneratorLoss.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I merged it, the ppl part is not nice. Also there is a normalization args that was not used anywhere, I will investigate to see if the normalization process disappeared by mistake
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
normalization was already not used a year ago
Line 228 in 7835130
def __init__(self, criterion, generator, normalization="sents", |
onmt/utils/loss.py
Outdated
""" | ||
|
||
def __init__(self, unlikelihood_coeff, ignore_index=-100): | ||
assert 0.0 < unlikelihood_coeff |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add an explicit message here?
onmt/utils/loss.py
Outdated
target.size(0), target.size(1), target.size(0) | ||
).permute(1, 2, 0) | ||
|
||
ctx_cands = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More explicit variable name? Or at least a comment?
@funboarder13920 @francoishernandez would it be worth updating wrt the v3 and merging or shall we drop ? |